package xworker.javafx.control;

import javafx.geometry.Orientation;
import javafx.scene.control.ScrollBar;
import org.xmeta.ActionContext;
import org.xmeta.Thing;
import xworker.javafx.beans.property.PropertyFactory;

public class ScrollBarActions {
    static{
        PropertyFactory.regist(ScrollBar.class, "maxProperty", o -> {
            ScrollBar obj = (ScrollBar) o;
            return obj.maxProperty();
        });
        PropertyFactory.regist(ScrollBar.class, "valueProperty", o -> {
            ScrollBar obj = (ScrollBar) o;
            return obj.valueProperty();
        });
        PropertyFactory.regist(ScrollBar.class, "visibleAmountProperty", o -> {
            ScrollBar obj = (ScrollBar) o;
            return obj.visibleAmountProperty();
        });
        PropertyFactory.regist(ScrollBar.class, "blockIncrementProperty", o -> {
            ScrollBar obj = (ScrollBar) o;
            return obj.blockIncrementProperty();
        });
        PropertyFactory.regist(ScrollBar.class, "unitIncrementProperty", o -> {
            ScrollBar obj = (ScrollBar) o;
            return obj.unitIncrementProperty();
        });
        PropertyFactory.regist(ScrollBar.class, "orientationProperty", o -> {
            ScrollBar obj = (ScrollBar) o;
            return obj.orientationProperty();
        });
        PropertyFactory.regist(ScrollBar.class, "minProperty", o -> {
            ScrollBar obj = (ScrollBar) o;
            return obj.minProperty();
        });
    }

	public static void init(ScrollBar s, Thing thing, ActionContext actionContext) {
		ControlActions.init(s, thing, actionContext);
		
        if(thing.valueExists("blockIncrement")){
            s.setBlockIncrement(thing.getDouble("blockIncrement"));
        }
        if(thing.valueExists("max")){
            s.setMax(thing.getDouble("max"));
        }
        if(thing.valueExists("min")){
            s.setMin(thing.getDouble("min"));
        }
        if(thing.valueExists("orientation")){
            s.setOrientation(Orientation.valueOf(thing.getString("orientation")));
        }
        if(thing.valueExists("unitIncrement")){
            s.setUnitIncrement(thing.getDouble("unitIncrement"));
        }
        if(thing.valueExists("value")){
            s.setValue(thing.getDouble("value"));
        }
	}
	
	public static ScrollBar create(ActionContext actionContext) {
		Thing self = actionContext.getObject("self");
		
		ScrollBar item = new ScrollBar();
		init(item, self, actionContext);
		actionContext.g().put(self.getMetadata().getName(), item);
		
		actionContext.peek().put("parent", item);
		for(Thing child : self.getChilds()) {
			child.doAction("create", actionContext);			
		}
		
		return item;
	}
}
